package com.jingdianjichi.user.controller;

import com.jingdianjichi.common.PageResponse;
import com.jingdianjichi.common.Result;
import com.jingdianjichi.user.entity.po.SysUserPo;
import com.jingdianjichi.user.entity.req.SysUserReq;
import com.jingdianjichi.user.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (SysUser)表控制层
 *
 * @author makejava
 * @since 2024-12-06 20:22:11
 */
@RestController
@RequestMapping("/sysUser")
@Api(tags = "Sys用户Controller")
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;

    /**
     * 分页查询
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public Result<PageResponse<SysUserPo>> queryByPage(@RequestBody SysUserReq sysUserReq) {
        return Result.ok(sysUserService.queryByPage(sysUserReq));
    }

    /**
     * 通过主键查询单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public Result<SysUserPo> queryById(@PathVariable("id") Long id) {
        return Result.ok(sysUserService.queryById(id));
    }

    /**
     * 新增数据
     */
    @PostMapping
    @ApiOperation("新增数据")
    public Result<SysUserPo> add(@RequestBody SysUserReq sysUserReq) {
        return Result.ok(sysUserService.insert(sysUserReq));
    }

    /**
     * 修改数据
     */
    @PutMapping
    @ApiOperation("修改数据")
    public Result<SysUserPo> edit(@RequestBody SysUserReq sysUserReq) {
        return Result.ok(sysUserService.update(sysUserReq));
    }

    /**
     * 删除数据
     */
    @DeleteMapping
    @ApiOperation("删除数据")
    public Result<Boolean> deleteById(Long id) {
        return Result.ok(sysUserService.deleteById(id));
    }

}

